<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 16/4/9
 * Time: 上午10:46
 * Describe:
 */

namespace common\helper;


class ArrayHelper extends \yii\helpers\ArrayHelper
{

    /**
     * @param $arr array
     * @return array
     *
     *  $arr = ['a', 'b', 'c', 'd', 'e', 'f'];
     *  $newArr = ArrayHelper::arrayToDict($arr);
     *
     *  $newArr ['a'=>'b', 'c'=>'d', 'e'=>'f']
     */
    public static function arrayToDict($arr)
    {
        return array_reduce(array_chunk($arr, 2), function ($s, $item) {
            return $s + [$item[0] => $item[1]];
        }, []);
    }

    public static function arrayToString($arr)
    {
        return print_r($arr, true);
    }

}